using Microsoft.EntityFrameworkCore;
using WebApiThird;
using WebApiThird.Common;
using WebApiThird.IService;
using WebApiThird.Model;
using WebApiThird.Service;
using Zack.ASPNETCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddMemoryCache();
builder.Services.AddDbContext<AppDbContext>(p => p.UseSqlServer(builder.Configuration.GetConnectionString("SqlServer"))
.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole())));

builder.Services.AddAutoMapper(typeof(AutoMapperProfile));
builder.Services.AddScoped<IStudentService, StudentService>();
builder.Services.AddScoped<IStudentFileService, StudentFileService>();
builder.Services.AddScoped<IMemoryCacheHelper,MemoryCacheHelper>();
builder.Services.AddScoped<IDistributedCacheHelper,DistributedCacheHelper>();
builder.Services.AddStackExchangeRedisCache(options =>
{
    options.InstanceName = builder.Configuration.GetSection("RedisConnection:Instance").Value;
    options.Configuration = builder.Configuration.GetSection("RedisConnection:Host").Value;
});
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();
//app.UseResponseCaching(); 服务器端缓存
app.MapControllers();

app.Run();
